﻿@model KPIS.GERP.Models.ICM.Received

@{
    ViewBag.Title = "แก้ใข [RC]";
}


@using (Html.BeginForm("Edit", "ReceiveParcel", FormMethod.Post, new { id = "form", @class = "form-horizontal" }))
{
      @Html.AntiForgeryToken()

    <div class="span12 block-button-menu-above">
        @Html.ButtonViewAll()
        @Html.ButtonSubmit()
    </div>

    @Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField, new { @class = "alert alert-error" })
    @Html.Partial("_EditorForm")

    @Html.HiddenFor(model => model.DnId, new { id="hdDnId"})
    @Html.HiddenFor(model=>model.ReceiveTypeId)
    @Html.HiddenFor(model=>model.WhId)
    @Html.HiddenFor(model => model.ReceiveDate)
    @Html.HiddenFor(model => model.RecordStatus)
    @Html.HiddenFor(model => model.CreatedWhen)
    @Html.HiddenFor(model => model.CreatedBy)
    
}



@section scripts {

    <script type="text/javascript" >


        $("form").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ต้องการบันทึก ใช่หรือไม่?", function (result) {
                if (result) {
                    var DnId = $("#ddlDn option:selected").val();
                    var Name = $("#txtRecName").val();

                    if (DnId == 0 || Name == "") {

                        if (DnId == 0) { $("#txtDN").show(); }
                        else { $("#txtDN").hide(); }

                        if (Name == "") { $("#txtName").show(); }
                        else { $("#txtName").hide(); }

                    } else {
                        currentForm.submit();
                    }
                }
            });
        });

        jQuery(function ($) {
            $("#ddlRecType").prop("disabled", true);
        });


        // Fetch Warehouse เมื่อเลือกใบตรวจรับ
        jQuery(function ($) {
            var DnId = $("#hdDnId").val();
            GetWarehouse(DnId);
        })

        function GetWarehouse(DnId) {
            if (DnId == 0) {
                $("#txtWhName").val("");
            } else {
                $.getJSON('@Url.Action("GetWarehouse","ReceiveParcel")?intDnId=' + DnId, null, function (data) {
                    $("#hdWhId").val(data.Id);
                    $("#txtWhName").val(data.Name);
                });
            }
        }

        $(document).ready(function () {
            var Type = $("#ddlRecType option:selected").val();
            if (Type == "3") {
                $("#dvDn").show();
                $("#dvWhByDn").show();
                $("#dvWh").hide();                
            }
            else {
                $("#dvDn").hide();
                $("#dvWhByDn").hide();
                $("#dvWh").show();
            }
        })

       
    </script>
}
